/*
 * Copyright 2008 Max Kugland
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.splink.library.utils {

	/**
	 * @author Max Kugland
	 */
	public class ClazzUtils {
		/**
		 * Creates an instance of the given type with the given constructor arguments. Note that
		 * the maximum number of arguments is 10.
		 * 
		 * @param type the Class to instantiate
		 * @param args the constructor arguments for the class to instantiate
		 */		public static function instance(type : Class, ...args) : Object {
			switch (args.length) {				case 0: 					return new type();				case 1: 					return new type(args[0]);				case 2: 					return new type(args[0], args[1]);				case 3: 					return new type(args[0], args[1], args[2]);				case 4: 					return new type(args[0], args[1], args[2], args[3]);				case 5: 					return new type(args[0], args[1], args[2], args[3], args[4]);				case 6: 					return new type(args[0], args[1], args[2], args[3], args[4], args[5]);				case 7: 					return new type(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);				case 8: 					return new type(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]);				case 9: 					return new type(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]);
				case 10: 
					return new type(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]);				default: 					throw new Error("Unsupported number of Constructor args: " + args.length);			}		}	}
}
